/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author User
 */
public class Proses {
    
    private Connection conn;

    public Proses(Connection kon) {
        this.conn = kon;

    }
 
       public List<Member> list() throws SQLException {
        PreparedStatement state = null;
        ResultSet result = null;
        try {
            conn.setAutoCommit(false);
            state = conn.prepareStatement("select id, nama, alamat, no_telp "
                    + "from member order by id");
            result = state.executeQuery();
            List<Member> list = new ArrayList<Member>();
            while (result.next()) {
                Member kat = new Member();
                kat.setId(result.getString("id"));
                kat.setNama(result.getString("nama"));
                kat.setAlamat(result.getString("alamat"));
                kat.setNo_telp(result.getString("no_telp"));
                list.add(kat);

            }

            conn.commit();
            return list;
        } catch (SQLException exception) {
            conn.rollback();
            throw exception;
        } finally {
            try {
                conn.setAutoCommit(true);
                if (state != null) {
                    state.close();
                }
            } catch (SQLException exception) {
                throw exception;
            }
        }
    }

}
